﻿using UnityEngine;
using System.Collections;

public class DontDestroyObject<T> : UILogBehaviour where T : UILogBehaviour
{
	private static T createdObj;
	protected virtual void Awake ()
	{
		if(createdObj != null)
		{
			Destroy(this.gameObject);
			return;
		}
		createdObj = this as T;
        DontDestroyOnLoad(this.gameObject);
	}

	protected virtual void OnDestroy()
	{
		if(createdObj == this)
		{
			createdObj = null;
		}
	}

	public static T instance
	{
		get
		{
			return createdObj;
		}
	}
}